package edu.njust.cma.controller;

import edu.njust.cma.config.ConstantConfig;
import edu.njust.cma.pojo.Result;
import edu.njust.cma.pojo.Submission;
import edu.njust.cma.DTO.TaskDecomposeRequestJSON;
import edu.njust.cma.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/labHead")
public class LabHeadController {

    /**
     * 分解一个任务为许多子任务
     */
    @Autowired
    TaskService taskService;

    @PostMapping("/decomposeTask")
    public Result decomposeTask(@RequestBody TaskDecomposeRequestJSON taskDecomposeRequestJSON) {
        if(taskService.decomposeTask(taskDecomposeRequestJSON)) {
            return Result.success();
        } else {
            return Result.error("分解任务失败");
        }
    }

    /**
     * 审核某个子任务
     */
    @PostMapping("/checkSubTask")
    public Result checkTask(@RequestBody Submission submission) {
        if(submission.getReviewStatus()== ConstantConfig.PASS){
            taskService.checkTaskPass(submission);
            return Result.success();
        }else if(submission.getReviewStatus()==ConstantConfig.NOT_PASS){
            taskService.checkTaskFail(submission);
            return Result.success();
        }else {
            System.out.println(submission);
            return Result.error("审核状态错误");
        }
    }

    /**
     * 获取所有未分解的任务
     */
    @GetMapping("/getTasksUnDecompose/{userId}")
    public Result getTasksUnDecompose(@PathVariable int userId) {
        return Result.success(taskService.getTasksUnDecompose(userId));
    }
    /**
     * 获取所有未提交的任务
     */
    @GetMapping("/getTasksUnSubmit/{labHeadUserId}")
    public Result getTasksUnSubmit(@PathVariable int   labHeadUserId) {
        return Result.success(taskService.getTasksUnSubmit(labHeadUserId));
    }
    /**
     * 获取所有未审核的任务
     */
    @GetMapping("/getTasksUnCheck/{labHeadUserId}")
    public Result getTasksUnCheck(@PathVariable int  labHeadUserId) {
        return Result.success(taskService.getsTasksUnCheck(labHeadUserId));
    }

    /**
     * 获取所有已经完成的任务
     */
    @GetMapping("/getTasksFinished/{labHeadUserId}")
    public Result getTasksFinished(@PathVariable  int  labHeadUserId) {
        return Result.success(taskService.getTasksFinished(labHeadUserId));
    }

    /**
     * 获取某个任务的额外要求子任务
     */
    @GetMapping("/getSubtaskAdditionalRequirement/{taskId}")
    public Result getSubtaskAdditionalRequirement(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskAdditionalRequirement(taskId));
    }

    /**
     * 获取某个任务的设备子任务
     */
    @GetMapping("/getSubtaskEquipment/{taskId}")
    public Result getSubtaskEquipment(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskEquipment(taskId));
    }

    /**
     * 获取某个任务的设施子任务
     */
    @GetMapping("/getSubtaskFacility/{taskId}")
    public Result getSubtaskFacility(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskFacility(taskId));
    }

    /**
     * 获取某个任务的比对子任务
     */
    @GetMapping("/getSubtaskComparison/{taskId}")
    public Result getSubtaskComparison(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskComparison(taskId));
    }

    /**
     * 获取某个任务的检验子任务
     */
    @GetMapping("/getSubtaskInspect/{taskId}")
    public Result getSubtaskInspect(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskInspect(taskId));
    }

    /**
     * 获取某个任务的样品子任务
     */
    @GetMapping("/getSubtaskSample/{taskId}")
    public Result getSubtaskSample(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskSample(taskId));
    }

    /**
     * 获取某个任务的模拟子任务
     */
    @GetMapping("/getSubtaskSimulation/{taskId}")
    public Result getSubtaskSimulation(@PathVariable Integer taskId) {
        return Result.success(taskService.getSubtaskSimulation(taskId));
    }
    /**
     * 获取某个任务的人员子任务
     */
    @GetMapping("/getStaffTask/{taskId}")
    public Result getStaffTask(@PathVariable Integer taskId) {
        return Result.success(taskService.getStaffTask(taskId));
    }
}
